package com.lechuang.common.result;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lechuang.common.request.PageRequest;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author liaoningbo
 * @since 2023-12-15
 */
@Data
@Accessors(chain = true)
public class PageResult<T> implements Serializable {
    private List<T> list;
    private T sum;
    private long total;
    private long pages;
    private int pageNum;
    private int pageSize;

    /**
     * <p>
     *     返回分页对象
     * </p>
     * @param list 数据
     * @param page 分页信息
     * @param pageRequest 分页查询请求
     * @param sum 合计
     * @author liaoningbo
     * @since 2024/1/11
     */
    public static <T,K,V> PageResult<T> result(List<T> list, Page<K> page, PageRequest<V> pageRequest, T sum){
        return new PageResult<T>()
                .setList(list)
                .setPageNum(pageRequest.getPageNum())
                .setPageSize(pageRequest.getPageSize())
                .setPages(page.getPages())
                .setTotal(page.getTotal())
                .setSum(sum);
    }
}
